<?php namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Services\Nav as sNav;
use App\Models\Nav   as mNav;
use Illuminate\Http\Request;
use DB;
class NavController extends BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		$navs = sNav::getNavList();

		return $this->view('nav.index',compact('navs'));
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		return $this->view('nav.create');
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store(Request $request)
	{
		try{
			$data = $request->all();
			
			mNav::create($data);

			DB::commit();

			return $this->redirect('nav.index');

		}catch(\Exception $e){

			DB::rollback();
			
			return $this->redirect('nav.index');
		}
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		mNav::where('id',$id)->update(['is_show' => mNav::DELETE_STATUS]);

		return $this->redirect('nav.index');
	}

}
